<template>
  <view class="content">
	<view class="row">
		<view class="lefttou">
			<image class="tou" src="../../static/gerenzhongxin/10.png" mode=""></image>
			企业预警
		</view>
		<text class="num title-num">{{ count.total }}</text>
	</view> 
	<view class="row p2010">
		<view class="w50">
			本周已处理
			<text class="num">{{ count.done }}</text>
		</view>
		<view class="w50">
			本周待处理
			<text class="num">{{ count.doing }}</text>
		</view>
	</view>
	<view class="today">
		今天
	</view>
    <view class="message-list">
      <wkiwi-swipe-action @endMove="endMove"  @clickItem="clickItem" :options="options" :messagesList="messagestoday"></wkiwi-swipe-action>
    </view>
	<view class="today">
		更早
	</view>
	<view class="message-list">
		<wkiwi-swipe-action @endMove="endMove"  @clickItem="clickItem" :options="options" :messagesList="messagesbefor"></wkiwi-swipe-action>
		<view class="more" v-if="isShowMore" @click="getFxWarning">加载更多</view>
		<view class="more" v-else>已全部加载</view>
	</view>
  </view>
</template>

<script>
import wkiwiSwipeAction from "../../components/catList/wkiwi-swipe-action.vue";
export default {
	components: { wkiwiSwipeAction },
	data() {
		return {
			count: {	// 统计数据
				total: 0,
				done: 0,
				doing: 0
			},
			options: [
				{
					text: "推送",
					style: {
						backgroundColor: "#C7C6CD"
					}
				},
				{
					text: "删除",
					style: {
						backgroundColor: "#dd524d"
					}
				}
			],
			messages: [
				{
					title: "安全隐患排除",
					url: [
						'../../static/fengxianyujing/icon-list.png'
						// "http://img1.3lian.com/gif/more/11/201212/58ec7c89b16c529fc9d0dc440a72e14d.jpg"
					],
					// message: "",
					time: "00:24",
					count: 2,
					stick: false,
					disabled: false, //是否禁止滑动
					type: 2 //普通用户类型消息
				}
			],
			messagestoday: [],
			messagesbefor:[],
			isShowMore: false,
			page: 1
		};
	},
	onLoad() {
		// #ifdef APP-PLUS
		/* 隐藏凸起图标 */
		var icon = plus.nativeObj.View.getViewById("icon");
		setTimeout(function() {
			if(icon){icon.hide();}
		}, 100);
		// #endif
		this.getFxWarning();
	},
	methods: {
		// 滑动
		endMove(data){
			let dir = data.dir;
			let sspid = data.data.ssp_id;
			if(dir == 'left') this.slideLeft(sspid);
			if(dir == 'right') this.slideRight(sspid);
		},
		// 左滑取消
		slideLeft(sspid){
			let _this = this
			uni.showModal({
				content: '您确认要取消吗？',
				success: function (res){
					if(res.confirm){
						uni.showLoading({
							title: '取消中'
						})
						uni.request({
							url: _this.$API.cancelDanger,
							method: "POST",
							data: {
								sspid,
								userid: uni.getStorageSync("userid")
							},
							header: _this.$API.get_head(),
							success: (res) => {
								uni.hideLoading();
								_this.messagestoday = _this.messagestoday.filter(it=>it.ssp_id != sspid);
								_this.messagesbefor = _this.messagesbefor.filter(it=>it.ssp_id != sspid);
							},
							fail: () => {
								uni.hideLoading()
								uni.showToast({
									title: "加载失败",
									icon: 'none'
								})
							}
						})
					}
				}
			})
		},
		// 右滑推送
		slideRight(sspid){
			let _this = this
			uni.request({
				url: _this.$API.pushDanger,
				method: "POST",
				data: {
					sspid,
					userid: uni.getStorageSync("userid")
				},
				header: _this.$API.get_head(),
				success: (res) => {
					uni.showToast({title: "推送成功"})
				},
				fail: () => {
					uni.showToast({
						title: "加载失败",
						icon: 'none'
					})
				}
			})
		},
		// 点击处理
		clickItem(item){
			uni.navigateTo({
				url: `../organization/finishTheTask?sspid=${item.ssp_id}`
			})
		},
		// 获取数据
		getFxWarning(){
			var _this = this;
			
			uni.showLoading({title: '加载中'});
			uni.request({
				url:_this.$API.getFxWarning,
				method:"POST",
				data: {
					page: _this.page
				},
				header: _this.$API.get_head(),
				success: (res) => {
					uni.hideLoading();
					
					// 统计数据处理
					_this.count.done = Number.parseInt(res.data.data.done_num);
					_this.count.doing = Number.parseInt(res.data.data.nodone_num);
					_this.count.total = _this.count.done + _this.count.doing;
					
					// 列表数据处理
					let data = res.data.data.list.rows;
					data.forEach(function(item,index){
						item['url'] =["../../static/gerenzhongxin/listfx.jpg"];
						item['stick'] = false;
						item['disabled'] = false;
						item['type'] = 2;
						
						// 根据addtime字段判断是今天还是更早，其中addtime为空的数据直接过滤掉
						if(item.addtime){
							if(_this.getTodayDate() == item.addtime.split(' ')[0]){
								_this.messagestoday.push(item);
							}else{
								_this.messagesbefor.push(item);
							}
						}
					});
					
					// 判断数据是否加载完毕
					_this.isShowMore = _this.page <= res.data.data.list.total;
					_this.page++;
				},
				fail: () => {
					uni.hideLoading();
					uni.showToast({
						title:"加载失败",
						icon:'none'
					})
				}
			});
		},
		// 获取当前日期
		getTodayDate(){
			let date = new Date();
			let year = date.getFullYear();
			let month= date.getMonth()+1;
			let day  = date.getDate();
			
			if(month < 10) year = '0'+month;
			if(day < 10) year = '0'+day;
			return `${year}-${month}-${day}`;
		}
	},
	onNavigationBarButtonTap(e) {
		if (e.index == 0) {
		  this.floatingMenuShow = !this.floatingMenuShow;
		}
	}
};
</script>

<style scoped="true" lang="scss" >
	.bumen{
		display: flex;
		justify-content: space-around;
		padding: 15upx 50upx 0;
		.uni-input{
			background:transparent;
			padding: 0;
		}
	}
	.today{
		color:#17a8f8;
		border-bottom:5upx solid #17a8f8;
		padding:10upx 20upx;
		font-size:30upx;
		margin:0 20upx 15upx;
	}
.row{
	display: flex;
	border:1upx solid #f2f2f2;
	align-items:center;
	background:#FFFFFF;
	padding: 10upx;
}
.lefttou{
	width:100%;
	display: flex;
	align-items: center;
}
.tou{
	width: 100upx;
	height: 100upx;
	margin-right: 10upx;
	border-radius: 50%;
	overflow: hiideen;
}
.w50{
	width:50%;
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding:0 50upx;
}
.num{
	border-radius:50%;
	background:#fb5656;
	color:#FFFFFF;
	display: inline-block;
	min-width:32upx;
	min-height: 32upx;
	line-height: 1.5;
	padding: 0 5rpx;
	text-align: center;
}
.p2010{
	padding: 20rpx 10rpx
}

.floating-menus {
  position: fixed;
  top: 0;
  right: 20upx;
  z-index: 10;
  opacity: 0;
  transition: all 0.4s;
  height: 0;
  overflow: hidden;
}
.floating-menus {
  &.show {
    opacity: 1;
    height: auto;
  }
  &.hidden {
    opacity: 0;
    height: 0;
  }
}
.more{
	text-align: center;
	padding-bottom: 40upx;
}
</style>
